package com.wnxy.consumer.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试
 */
@RestController
@RequestMapping("/test")
@Slf4j
public class TestController {

    /**
     * 测试降级熔断
     */
    @GetMapping("/find/{id}")
    @HystrixCommand(fallbackMethod = "errorFallback")
    public String find(@PathVariable("id")Integer id) throws Exception {
        if (id < 10) {
            throw new Exception();
        }
        return "ok";
    }

    // 降级方法
    public String errorFallback(@PathVariable("id")Integer id){
        return "降级方法";
    }

}